// pages/search1/search1.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        List: [],
        content:'',
        thisContent: '',
        type: '',
        pageNum: 1,
        totalPages: 1   
    },

    //input输入事件
    input(e){
        this.setData({
            content: e.detail.value
        })
        console.log("搜索结果",this.data.content)
    },

    // search点击搜索触发的事件
    search(e){
      this.setData({
        pageNum: 1,
      })
        wx.request({
            url: 'https://www.hschuangsai.com/search/condition',
            data: {
              captain: "",
              department: "",
              name: this.data.content,
              pageParam: {
                orderBy: "id asc",
                pageNum: this.data.pageNum,
                pageSize: 10
              },
              tag: "",
              type: "1"
            },
            method: "POST",
            success: (result) => {
              
                this.setData({
                    List: result.data.data.list,
                    thisContent: this.data.content,
                    totalPages: result.data.data.pages
                })
                console.log("搜索结果",result)
                if(result.data.data.total==0){
                  wx.showToast({
                    title: '暂时没有相关的通知公告，换个关键词试试吧！',
                    icon:"none"
                  })
                }
            }
      })
    
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            content: options.content,
            type: options.type,
            pageNum: 1
        })
        wx.request({
          url: 'https://www.hschuangsai.com/search/condition',
          data: {
            captain: "",
            department: "",
            name: this.data.content,
            pageParam: {
              orderBy: "id asc",
              pageNum: this.data.pageNum,
              pageSize: 5
            },
            tag: "",
            type: "1"
          },
          method: "POST",
          success: (result) => {
              console.log(result.data)
              this.setData({
                List: result.data.data.list,
                thisContent: this.data.content,
                totalPages: result.data.data.pages
              })
              console.log(result)
              if(result.data.data.total==0){
                wx.showToast({
                  title: '暂时没有相关的通知公告，换个关键词试试吧！',
                  icon:"none"
                })
              }
          }
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      this.data.pageNum+=1
      if(this.data.pageNum>this.data.totalPages){
        console.log('没有更多数据了')
      }else{
      wx.request({
        url: 'https://www.hschuangsai.com/search/condition',
        data: {
          captain: "",
          department: "",
          name: this.data.thisContent,
          pageParam: {
            orderBy: "id asc",
            pageNum: this.data.pageNum,
            pageSize: 10
          },
          tag: "",
          type: "1"
        },
        method: "POST",
        success: (result) => {
            //console.log(result.data)
            this.setData({
              List: [...this.data.List,...result.data.data.list]
            })
        }
      })
      }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})